package mage.factory.rules;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class RuleParser {
	
static List<RuleElement> rules_db = new ArrayList<RuleElement>(Arrays.asList(new RuleElement[]{

new RuleElement("Flying", "", "this.addAbility(FlyingAbility.getInstance());", ""),
new RuleElement("First strike", "", "\t\this.addAbility(FirstStrikeAbility.getInstance());", ""),
new RuleElement("Protection from white", "", "FilterCard filter = new FilterCard(\"White\");\n\t\tfilter.getColor().setWhite(true);\n\t\tfilter.setUseColor(true);\n\t\tthis.addAbility(new ProtectionAbility(filter));", ""),	
new RuleElement("Protection from black", "", "FilterCard filter = new FilterCard(\"White\");\n\t\tfilter.getColor().setBlack(true);\n\t\tfilter.setUseColor(true);\n\t\tthis.addAbility(new ProtectionAbility(filter));", ""),	
new RuleElement("Protection from green", "", "FilterCard filter = new FilterCard(\"White\");\n\t\tfilter.getColor().setGreen(true);\n\t\tfilter.setUseColor(true);\n\t\tthis.addAbility(new ProtectionAbility(filter));", ""),	
new RuleElement("Protection from red", "", "FilterCard filter = new FilterCard(\"White\");\n\t\tfilter.getColor().setRed(true);\n\t\tfilter.setUseColor(true);\n\t\tthis.addAbility(new ProtectionAbility(filter));", ""),	
new RuleElement("Protection from blue", "", "FilterCard filter = new FilterCard(\"White\");\n\t\tfilter.getColor().setBlue(true);\n\t\tfilter.setUseColor(true);\n\t\tthis.addAbility(new ProtectionAbility(filter));", ""),	
new RuleElement("Defender", "", "this.addAbility(DefenderAbility.getInstance());", ""),
new RuleElement("Defender, flying", "", "this.addAbility(DefenderAbility.getInstance());\n\t\tthis.addAbility(FlyingAbility.getInstance());", ""),

new RuleElement("Trample", "", "this.addAbility(TrampleAbility.getInstance());", ""),
new RuleElement("Enchant creature", "", "TargetPermanent auraTarget = new TargetCreaturePermanent();\n\t\tthis.getSpellAbility().addTarget(auraTarget);\n\t\tthis.getSpellAbility().addEffect(new AttachEffect(Outcome.BoostCreature));\n\t\tAbility ability = new EnchantAbility(auraTarget.getTargetName());\n\t\tthis.addAbility(ability);", ""),
	





		
new RuleElement("", "", "", "")
}));
	
	public String getPreConstructor(String text) {
		return this.match(text).getPre_constructor();
	}
	public String getConstructureDetails(String text) {
		return "\t\t"+this.match(text).getConstructor_detail()+"\n";
	}
	public String getAdditionalMethods(String text) {
		return this.match(text).getAdditional_block();
	}
	protected RuleElement match(String text){
		for (RuleElement re : this.rules_db) {
			if(re.getText().equalsIgnoreCase(text)){
				return re;
			}
		}
		return new RuleElement(text,"","","");
	}
}

class RuleElement{
	protected String text = "";
	protected String pre_constructor = "";
	protected String constructor_detail = "";
	protected String additional_block = "";
	public RuleElement(String text, String pre_constructor, String constructor_detail, String additional_block){
		this.text=text;
		this.pre_constructor=pre_constructor;
		this.constructor_detail=constructor_detail;
		this.additional_block=additional_block;
	}
	public String getText() {
		return text;
	}
	public void setText(String text) {
		this.text = text;
	}
	public String getPre_constructor() {
		return pre_constructor;
	}
	public void setPre_constructor(String pre_constructor) {
		this.pre_constructor = pre_constructor;
	}
	public String getConstructor_detail() {
		return constructor_detail;
	}
	public void setConstructor_detail(String constructor_detail) {
		this.constructor_detail = constructor_detail;
	}
	public String getAdditional_block() {
		return additional_block;
	}
	public void setAdditional_block(String additional_block) {
		this.additional_block = additional_block;
	}
	
}